package com.budwk.app.sys.controllers.sys;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.budwk.app.base.filedetection.FileDetection;
import com.budwk.app.oss.models.SysOss;
import com.budwk.app.oss.services.SysOssService;
import com.budwk.app.popo.service.PopoInterfaceService;
import com.budwk.app.sqfw.annotation.FieldValueAnnotationProcessor;
import com.budwk.app.sqfw.bo.Sqfw_formSummaryForAdminBO;
import com.budwk.app.sqfw.models.HouseInfo;
import com.budwk.app.sqfw.models.Sqfw_formSummary;
import com.budwk.app.sqfw.models.Sqfw_servicerecord;
import com.budwk.app.sqfw.services.SqfwPoUserService;
import com.budwk.app.sqfw.services.SqfwServicerecordService;
import com.budwk.app.sqfwV2.dto.vo.SummaryQueryReqVo;
import com.budwk.app.sys.bo.SysUserDownloadBO;
import com.budwk.app.sys.dto.SysUserForAdminDTO;
import com.budwk.app.sys.models.Sys_role;
import com.budwk.app.sys.models.Sys_unit;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.*;
import com.budwk.app.sys.vo.SysUnitVO;
import com.budwk.app.sys.vo.SysUserAreaVO;
import com.budwk.app.sys.vo.SysUserVO;
import com.budwk.app.util.adminUtils.CommonCheckUtils;
import com.budwk.app.util.poiUtils.SqfwInfoDataEasyExcelListener;
import com.budwk.starter.common.constant.GlobalConstant;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.openapi.enums.ParamIn;
import com.budwk.starter.common.page.PageUtil;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.excel.utils.ExcelUtil;
import com.budwk.starter.log.annotation.SLog;
import com.budwk.starter.security.utils.SecurityUtil;
import com.google.common.collect.Maps;
import jodd.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jim.core.packets.UserReqBody;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.lang.random.R;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.*;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * @author wizzer@qq.com
 */
@IocBean
@At("/platform/sys/user")
@SLog(tag = "用户管理")
@ApiDefinition(tag = "用户管理")
@Slf4j
public class SysUserController {
    @Inject
    private SysUnitService sysUnitService;
    @Inject
    private SysUserService sysUserService;
    @Inject
    private SysRoleService sysRoleService;
    @Inject
    private SysPostService sysPostService;
    @Inject
    private SysGroupService sysGroupService;

    @Inject
    private PopoInterfaceService popoInterfaceService;

    @Inject
    private SqfwPoUserService sqfwPoUserService;

    @Inject
    private SqfwServicerecordService sqfwServicerecordService;

    @Inject
    private FileDetection fileDetection;

    @Inject
    private SysOssService sysOssService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "查询同一单位的所有用户信息")
    @SaCheckLogin
    public Result<Pagination> listCommonUnitUser(@Param("..") SummaryQueryReqVo reqVo) {
        return Result.data(sysUserService.listCommonUnitUser(reqVo));
    }

    @At("/unitlist")
    @Ok("json")
    @GET
    @SLog(value = "获取单位树形列表查询:${name}")
    @ApiOperation(name = "Vue3树形列表查询")
    @ApiFormParams(
            {
                    @ApiFormParam(name = "name", example = "", description = "单位名称")
            }
    )
    @ApiResponses(
            implementation = Pagination.class
    )
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    public Result<?> getUnitList(
            @Param("name") String name) {
        Cnd cnd = Cnd.NEW();
        // 增加5级权限
        CommonCheckUtils.checkAreaRangeCnd(cnd);
        // 非管理员显示所属单位及下级单位
        if (!StpUtil.hasRole(GlobalConstant.DEFAULT_SYSADMIN_ROLECODE)) {
            Sys_user sysUser = sysUserService.fetch(Cnd.where(Sys_user::getId, "=", SecurityUtil.getUserId()));
            Sys_unit unit = sysUnitService.fetch(Cnd.where(Sys_unit::getId, "=", sysUser.getUnitId()));
            cnd.and("path", "like", unit.getPath() + "%");
        }
        if (Strings.isNotBlank(name)) {
            cnd.and("name", "like", "%" + name + "%");
        }
        cnd.and("disable", "!=", true);
        cnd.asc("location");
        cnd.asc("path");
        return Result.success().addData(sysUnitService.query(cnd));
    }

    @At("/unit")
    @Ok("json")
    @GET
    @SLog(value = "获取单位树数据")
    @ApiOperation(name = "Vue2获取单位树数据")
    @ApiImplicitParams
    @ApiResponses
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    public Result<?> getUnitTree() {
        String pid = "";
        List<Sys_unit> list = new ArrayList<>();
        if (StpUtil.hasRole(GlobalConstant.DEFAULT_SYSADMIN_ROLECODE)) {
            Cnd cnd = Cnd.NEW();
            cnd.asc("location").asc("path");
            list = sysUnitService.query(cnd);
        } else {
            //如果非超级管理员,查找最顶级单位
            Sys_unit unit = sysUnitService.fetch(sysUnitService.getMasterCompanyId(SecurityUtil.getUnitId()));
            pid = unit.getParentId();
            list = sysUnitService.query(Cnd.where("path", "like", unit.getPath() + "%").asc("location").asc("path"));
        }
        NutMap unitMap = NutMap.NEW();
        for (Sys_unit unit : list) {
            if (StringUtils.isBlank(unit.getParentId())) unit.setParentId("");
            List<Sys_unit> list1 = unitMap.getList(unit.getParentId(), Sys_unit.class);
            if (list1 == null) {
                list1 = new ArrayList<>();
            }
            list1.add(unit);
            unitMap.put(unit.getParentId(), list1);
        }
        return Result.data(getTree(unitMap, pid));
    }

    private List<NutMap> getTree(NutMap unitMap, String pid) {
        List<NutMap> treeList = new ArrayList<>();
        List<Sys_unit> subList = unitMap.getList(pid, Sys_unit.class);
        for (Sys_unit unit : subList) {
            NutMap map = Lang.obj2nutmap(unit);
            map.put("label", unit.getName());
            if (unit.isHasChildren() || (unitMap.get(unit.getId()) != null)) {
                map.put("children", getTree(unitMap, unit.getId()));
            }
            treeList.add(map);
        }
        return treeList;
    }

    @At("/post")
    @Ok("json")
    @GET
    @SLog(value = "获取职务列表")
    @ApiOperation(name = "获取职务列表")
    @ApiImplicitParams
    @ApiResponses
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    public Result<?> post(HttpServletRequest req) {
        return Result.data(sysPostService.query());
    }

    @At("/count/{unitPath}")
    @Ok("json")
    @GET
    @SLog(value = "获取职务列表")
    @ApiOperation(name = "获取职务列表")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "unitPath", description = "单位PATH", in = ParamIn.PATH)
            }
    )
    @ApiResponses
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    public Result<?> count(@Param("unitPath") String unitPath, HttpServletRequest req) {
        int allNumber = sysUserService.count(Cnd.where("unitPath", "like", unitPath + "%"));
        int enabledNumber = sysUserService.count(Cnd.where("unitPath", "like", unitPath + "%").and("disabled", "=", false));
        int disabledNumber = sysUserService.count(Cnd.where("unitPath", "like", unitPath + "%").and("disabled", "=", true));
        return Result.data(NutMap.NEW().addv("allNumber", allNumber).addv("enabledNumber", enabledNumber).addv("disabledNumber", disabledNumber));
    }

    @At("/list")
    @Ok("json:{locked:'^(password|salt)$',ignoreNull:false}")
    @POST
    @SLog(value = "获取用户列表")
    @ApiOperation(name = "获取用户列表")
    @ApiFormParams(
            {
                    @ApiFormParam(name = "unitPath", example = "", description = "单位PATH"),
                    @ApiFormParam(name = "postId", example = "", description = "职务ID"),
                    @ApiFormParam(name = "username", example = "", description = "用户姓名"),
                    @ApiFormParam(name = "loginname", example = "", description = "用户名"),
                    @ApiFormParam(name = "mobile", example = "", description = "手机号码"),
                    @ApiFormParam(name = "disabled", example = "", description = "用户状态", type = "boolean"),
                    @ApiFormParam(name = "query", example = "", description = "查询关键词"),
                    @ApiFormParam(name = "beginTime", example = "", description = "开始时间", type = "long"),
                    @ApiFormParam(name = "endTime", example = "", description = "结束时间", type = "long"),
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "createdAt", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            }
    )
    @ApiResponses(
            implementation = Pagination.class
    )
    // @SaCheckPermission("sys.manage.user")  因为前端需要获取所有的用户，所以先把这个注解去掉
    @SaCheckLogin
    public Result<?> list(@Param("beginTime") Long beginTime, @Param("endTime") Long endTime, @Param("disabled") Boolean disabled, @Param("mobile") String mobile, @Param("unitPath") String unitPath, @Param("postId") String postId, @Param("username") String username, @Param("loginname") String loginname, @Param("query") String query, @Param("pageNo") int pageNo, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
        Cnd cnd = Cnd.NEW();
        // 增加5级权限
        CommonCheckUtils.checkAreaRangeCnd(cnd);

        if (Strings.isNotBlank(unitPath)) {
            cnd.and("unitPath", "like", unitPath + "%");
        }
        if (Strings.isNotBlank(postId)) {
            cnd.and("postId", "=", postId);
        }
        if (Strings.isNotBlank(username)) {
            cnd.and("username", "like", "%" + username + "%");
        }
        if (Strings.isNotBlank(loginname)) {
            cnd.and("loginname", "like", "%" + loginname + "%");
        }
        if (Strings.isNotBlank(mobile)) {
            cnd.and("mobile", "like", "%" + mobile + "%");
        }
        if (beginTime != null && endTime != null) {
            cnd.and("createdAt", ">=", beginTime);
            cnd.and("createdAt", "<=", endTime);
        }
        if (disabled != null) {
            cnd.and("disabled", "=", disabled);
        }
        if (Strings.isNotBlank(query)) {
            cnd.and(Cnd.exps("loginname", "like", "%" + query + "%").or("username", "like", "%" + query + "%")
                    .or("mobile", "like", "%" + query + "%"));
        }
        /*if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
            cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
        }*/
        cnd.orderBy("unitPath", "ASC");
        cnd.orderBy("createdAt", "DESC");
        Pagination pagination = sysUserService.listPageLinks(pageNo, pageSize, cnd, "^(unit|roles|createdByUser|updatedByUser)$");
        return Result.data(pagination);
    }

    @At("/number")
    @Ok("json")
    @GET
    @SLog(value = "获取员工编号")
    @ApiOperation(name = "获取员工编号")
    @ApiImplicitParams
    @ApiResponses
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    public Result<?> number(HttpServletRequest req) {
        Sql sql = Sqls.create("select max(CAST(serialNo as int)) from shequ.sys_user");
        sql.setCallback(Sqls.callback.integer());
        sysUserService.dao().execute(sql);
        return Result.data(sql.getInt() + 1);
    }

    @At("/group")
    @Ok("json")
    @GET
    @SLog(value = "根据公司id获取公司(或为上级单位)角色组及角色:${unitId}")
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    @ApiOperation(name = "获取公司(或为上级单位)角色组及角色")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "unitId", description = "单位ID", required = true, check = true)
            }
    )
    @ApiResponses
    public Result<?> group(@Param("unitId") String unitId, HttpServletRequest req) {
        List list = new ArrayList();
        list.add("48c7acde57134c759e2cc45cd04d043c");
        list.add(unitId);

        if (StpUtil.hasPermission("sys.manage.role.system")) {
            //有系统公用权限可分配公用角色
            return Result.data(sysGroupService.query(Cnd.where("unitId", "=",
                            sysUnitService.getMasterCompanyId(unitId)).or("unitid", "in", list).asc("createdAt"), "roles",
                    // 排除public角色,公共角色无需分配即可拥有
                    Cnd.where("code", "<>", "public")));
        } else {
            return Result.data(sysGroupService.query(Cnd.where("unitId", "=",
                            sysUnitService.getMasterCompanyId(unitId)).asc("createdAt"), "roles",
                    // 排除public角色,公共角色无需分配即可拥有
                    Cnd.where("code", "<>", "public")));
        }
    }

    @At("/create")
    @Ok("json")
    @POST
    @SLog(value = "新增用户,用户名:${user.loginname}")
    @ApiOperation(name = "新增用户")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "roleIds", description = "角色ID数组")
            },
            implementation = Sys_user.class
    )
    @ApiResponses
    //@SaCheckPermission("sys.manage.user.create")
    public Result<?> create(@Param("..") Sys_user user, @Param("roleIds") String[] roleIds) {
        String adminSysUserId = SecurityUtil.getUserId();
        int checkNumber = sysUserService.count(Cnd.where("serialNo", "=", user.getSerialNo()));
        if (checkNumber > 0) {
            return Result.error("用户编号已存在");
        }
        if (Strings.isNotBlank(user.getMobile())) {
            checkNumber = sysUserService.count(Cnd.where("mobile", "=", user.getMobile()));
            if (checkNumber > 0) {
                return Result.error("手机号已存在");
            }
        }
        checkNumber = sysUserService.count(Cnd.where("loginname", "=", Strings.trim(user.getLoginname())));
        if (checkNumber > 0) {
            return Result.error("用户名已存在");
        }
        if (Strings.isNotBlank(user.getEmail())) {
            checkNumber = sysUserService.count(Cnd.where("email", "=", Strings.trim(user.getEmail())));
            if (Strings.isNotBlank(Strings.trim(user.getEmail())) && checkNumber > 0) {
                return Result.error("邮箱已存在");
            }
        }

        // wzy 2023-5-10 在新增系统用户的时候需要给用户新增一个泡泡账户
        // String popoUserId = popoInterfaceService.addPopoUser(user.getLoginname(), user.getUsername(), null, "123456", null);
        // if (StringUtils.isBlank(popoUserId)) return Result.error("创建泡泡用户失败，请重试");

        // user.setCreatedBy(SecurityUtil.getUserId());
        Sys_user newSysUser = sysUserService.create(user, roleIds);

        // wzy 2023-06-02 暂停泡泡用户关联
        // Sqfw_po_user sqfwPoUser = sqfwPoUserService.insertSysPopoUserRelationBySys(user.getId(), popoUserId, adminSysUserId);

        return Result.success();
    }

    @At("/update")
    @Ok("json")
    @POST
    @SLog(value = "修改用户,用户名:${user.loginname}")
    @ApiOperation(name = "修改用户")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "roleIds", description = "角色ID数组")
            },
            implementation = Sys_user.class
    )
    @ApiResponses
    @SaCheckLogin
    public Result<?> update(@Param("..") Sys_user user, @Param("roleIds") String[] roleIds) {
        int checkNumber = sysUserService.count(Cnd.where("serialNo", "=", user.getSerialNo()).and("id", "<>", user.getId()));
        if (checkNumber > 0) {
            return Result.error("用户编号已存在");
        }
        if (Strings.isNotBlank(user.getMobile())) {
            checkNumber = sysUserService.count(Cnd.where("mobile", "=", user.getMobile()).and("id", "<>", user.getId()));
            if (checkNumber > 0) {
                return Result.error("手机号已存在");
            }
        }
        if (Strings.isNotBlank(user.getLoginname())) {
            checkNumber = sysUserService.count(Cnd.where("loginname", "=", Strings.trim(user.getLoginname())).and("id", "<>", user.getId()));
            if (checkNumber > 0) {
                return Result.error("用户名已存在");
            }
        }
        if (Strings.isNotBlank(user.getEmail())) {
            checkNumber = sysUserService.count(Cnd.where("email", "=", Strings.trim(user.getEmail())).and("id", "<>", user.getId()));
            if (Strings.isNotBlank(Strings.trim(user.getEmail())) && checkNumber > 0) {
                return Result.error("邮箱已存在");
            }
        }
        if (user.isDisabled() && GlobalConstant.DEFAULT_SYSADMIN_LOGINNAME.equals(Strings.trim(user.getLoginname()))) {
            return Result.error("超级管理员不可禁用");
        }
        user.setUpdatedBy(SecurityUtil.getUserId());
        sysUserService.update(user, roleIds);
        return Result.success();
    }

    @At("/get/{id}")
    @Ok("json:{locked:'^(password|salt)$',ignoreNull:false}")
    @GET
    @SLog(value = "根据id获取用户信息:${id}")
    //@SaCheckPermission("sys.manage.user")
    @SaCheckLogin
    @ApiOperation(name = "获取用户信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", description = "用户ID", in = ParamIn.PATH)
            }
    )
    @ApiResponses
    public Result<?> getData(String id, HttpServletRequest req) {
        Sys_user user = sysUserService.fetch(id);
        if (user == null) {
            return Result.error(ResultCode.NULL_DATA_ERROR);
        }
        user = sysUserService.fetchLinks(user, "^(unit|roles)$");
        List<Sys_role> roles = user.getRoles();
        List<String> roleIds = new ArrayList<>();
        for (Sys_role role : roles) {
            roleIds.add(role.getId());
        }
        return Result.data(NutMap.NEW().addv("user", user).addv("roleIds", roleIds));
    }

    @At("/reset_pwd/{id}")
    @Ok("json")
    @GET
    @SaCheckPermission("sys.manage.user.update")
    @ApiOperation(name = "重置用户密码")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", description = "用户ID", in = ParamIn.PATH)
            }
    )
    @ApiResponses
    public Result<?> resetPwd(String id, HttpServletRequest req) {
        return Result.data(sysUserService.resetPwd(id));
    }


    @At("/disabled")
    @Ok("json")
    @POST
    @SaCheckPermission("sys.manage.user.update")
    @SLog(value = "启用禁用:${loginname}")
    @ApiOperation(name = "启用禁用")
    @ApiFormParams(
            {
                    @ApiFormParam(name = "id", description = "主键ID", required = true),
                    @ApiFormParam(name = "loginname", description = "用户姓名", required = true),
                    @ApiFormParam(name = "disabled", description = "disabled=true禁用", required = true)
            }
    )
    @ApiResponses
    public Result<?> changeDisabled(@Param("id") String id, @Param("loginname") String loginname, @Param("disabled") boolean disabled, HttpServletRequest req) {
        if (GlobalConstant.DEFAULT_SYSADMIN_LOGINNAME.equals(loginname)) {
            return Result.error("超级管理员不可禁用");
        }
        int res = sysUserService.update(Chain.make("disabled", disabled), Cnd.where("id", "=", id));
        sysUserService.cacheRemove(id);
        if (res > 0) {
            if (disabled) {
                req.setAttribute("_slog_msg", "禁用");
            } else {
                req.setAttribute("_slog_msg", "启用");
            }
            return Result.success();
        }
        return Result.error();
    }

    @At("/delete/{id}")
    @Ok("json")
    @DELETE
    //@SaCheckPermission("sys.manage.user.delete")
    @SLog(value = "删除用户:${loginname}")
    @ApiOperation(name = "删除用户")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", description = "主键ID", in = ParamIn.PATH)
            }
    )
    @ApiFormParams(
            {
                    @ApiFormParam(name = "loginname", description = "用户名", required = true, check = true)
            }
    )
    @ApiResponses
    public Result<?> delete(String id, @Param("loginname") String loginname, HttpServletRequest req) {
        if (GlobalConstant.DEFAULT_SYSADMIN_LOGINNAME.equals(loginname)) {
            return Result.error("超级管理员不可删除");
        }
        sysUserService.deleteUser(id);
        Sys_user sysUser = sysUserService.getUserById(id);
        Cnd cnd = Cnd.NEW();
        cnd.and("customer_phone", "=", sysUser.getLoginname());
        List<Sqfw_servicerecord> list = sqfwServicerecordService.query(cnd);
        for (Sqfw_servicerecord sqfwServicerecord : list) {
            sqfwServicerecordService.deleteServiceOrderLogic(sqfwServicerecord.getId()
            );
        }
        return Result.success();
    }

    @At("/delete_more")
    @Ok("json")
    @POST
    @SLog(value = "删除用户:${ids}")
    @ApiOperation(name = "删除用户")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "ids", description = "用户ID数组", required = true, check = true),
                    @ApiFormParam(name = "names", description = "用户名称数组", required = true, check = true)
            }
    )
    @ApiResponses
    @SaCheckPermission("sys.manage.user.delete")
    public Result<?> create(@Param("ids") String[] ids, @Param("names") String[] names) {
        String superadminId = "";
        Sys_user user = sysUserService.fetch(Cnd.where("loginname", "=", GlobalConstant.DEFAULT_SYSADMIN_LOGINNAME));
        if (user != null) {
            superadminId = user.getId();
        }
        if (ids != null) {
            for (String id : ids) {
                if (superadminId.equals(id)) {
                    return Result.error("超级管理员用户不可删除");
                }
                sysUserService.deleteUser(id);
            }
        }
        return Result.success();
    }

    @At("/export")
    @Ok("void")
    @POST
    @SLog(value = "导出用户数据")
    @ApiOperation(name = "导出用户数据")
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "unitPath", example = "", description = "单位PATH"),
                    @ApiImplicitParam(name = "postId", example = "", description = "职务ID"),
                    @ApiImplicitParam(name = "username", example = "", description = "用户姓名"),
                    @ApiImplicitParam(name = "loginname", example = "", description = "用户名"),
                    @ApiImplicitParam(name = "mobile", example = "", description = "手机号码"),
                    @ApiImplicitParam(name = "disabled", example = "", description = "用户状态", type = "boolean"),
                    @ApiImplicitParam(name = "query", example = "", description = "查询关键词"),
                    @ApiImplicitParam(name = "beginTime", example = "", description = "开始时间", type = "long"),
                    @ApiImplicitParam(name = "endTime", example = "", description = "结束时间", type = "long"),
                    @ApiImplicitParam(name = "query", example = "", description = "查询关键词")
            }
    )
    @ApiResponses
    @SaCheckPermission("sys.manage.user.export")
    public void export(@Param("disabled") Boolean disabled, @Param("beginTime") Long beginTime, @Param("endTime") Long endTime, @Param("mobile") String mobile, @Param("loginname") String loginname, @Param("username") String username, @Param("unitPath") String unitPath, @Param("postId") String postId, @Param("query") String query, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy, HttpServletRequest req, HttpServletResponse response) {
        Cnd cnd = Cnd.NEW();
        if (Strings.isNotBlank(unitPath)) {
            cnd.and("unitPath", "like", unitPath + "%");
        }
        if (Strings.isNotBlank(postId)) {
            cnd.and("postId", "=", postId);
        }
        if (Strings.isNotBlank(username)) {
            cnd.and("username", "like", "%" + username + "%");
        }
        if (Strings.isNotBlank(loginname)) {
            cnd.and("loginname", "like", "%" + loginname + "%");
        }
        if (Strings.isNotBlank(mobile)) {
            cnd.and("mobile", "like", "%" + mobile + "%");
        }
        if (beginTime != null && endTime != null) {
            cnd.and("createdAt", ">=", beginTime);
            cnd.and("createdAt", "<=", endTime);
        }
        if (disabled != null) {
            cnd.and("disabled", "=", disabled);
        }
        if (Strings.isNotBlank(query)) {
            cnd.and(Cnd.exps("loginname", "like", "%" + query + "%").or("username", "like", "%" + query + "%")
                    .or("mobile", "like", "%" + query + "%"));
        }
        if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
            cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
        }
        try {
            List<Sys_user> list = sysUserService.query(cnd, "^(unit|post)$");
            ExcelUtil<Sys_user> util = new ExcelUtil<>(Sys_user.class);
            util.exportExcel(response, list, "用户数据");
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    @At("/importData")
    @Ok("json")
    @POST
    @SLog(value = "导入用户数据")
    @ApiOperation(name = "导入用户数据")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "Filedata", example = "", description = "文件表单对象名"),
                    @ApiFormParam(name = "updateSupport", example = "", description = "是否覆盖"),
            },
            mediaType = "multipart/form-data"
    )
    @ApiResponses
    @SaCheckPermission("sys.manage.user.import")
//    @AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
    @AdaptBy(type = UploadAdaptor.class, args = {"${app.root}/WEB-INF/cloudfile/temp"})
    public Result<?> importData(@Param("Filedata") TempFile tf, @Param("pwd") String pwd, @Param(value = "updateSupport", df = "false") Boolean updateSupport, HttpServletRequest req, HttpServletResponse response) throws Exception {
        ExcelUtil<Sys_user> util = new ExcelUtil<>(Sys_user.class);
        List<Sys_user> list = util.importExcel(tf.getInputStream());
        return Result.success(sysUserService.importUser(list, pwd, updateSupport, SecurityUtil.getUserId()));
    }

    @At("/importTemplate")
    @Ok("void")
    @POST
    @SLog(value = "导入数据模版")
    @ApiOperation(name = "导入数据模版")
    @ApiImplicitParams
    @ApiResponses
    @SaCheckLogin
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Sys_user> util = new ExcelUtil<>(Sys_user.class);
        util.importTemplateExcel(response, "用户数据");
    }

    @At("/addPopoUser")
    @Ok("json")
    @GET
    @SLog(value = "根据系统用户id添加泡泡用户")
    @ApiOperation(name = "根据系统用户id添加泡泡用户")
    @ApiFormParams(@ApiFormParam(name = "sysUserId", example = "", description = "系统用户id"))
    @ApiResponses
    public Result<?> addPopoUser(@Param("sysUserId") String sysUserId) {
        String popoUid = sysUserService.addPopoUser(sysUserId, sysUserId);
        if (StringUtils.isNotBlank(popoUid)) {
            Map<String, String> dataMap = new HashMap<>();
            dataMap.put("popoUid", popoUid);
            return Result.success(dataMap);
        }
        return Result.error("创建失败");
    }

    @At("/getCurCompanyUserList")
    @Ok("json")
    @GET
    @SLog(value = "根据当前用户查询本组织的人员信息")
    @ApiOperation(name = "根据当前用户查询本组织的人员信息")
    @ApiFormParams(@ApiFormParam(name = "sysUserId", example = "", description = "系统用户id"))
    @ApiResponses
    public Result<?> getCurCompanyUserList(@Param("sysUserId") String sysUserId, @Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize) {
        if (pageSize == null) pageSize = 100;
        Pagination pagination = sysUserService.getCurCompanyUserList(sysUserId, pageNo, pageSize);
        return Result.data(pagination);
    }

    @At("/updateUserSignatureUrl")
    @Ok("json")
    @POST
    @SLog(value = "更新用户的签名")
    @ApiOperation(name = "更新用户的签名")
    @ApiResponses
    @SaCheckLogin
    public Result<?> updateUserSignatureUrl(@Param("signatureUrl") String signatureUrl) {
        String userId = SecurityUtil.getUserId();

        Sys_user sysUser = sysUserService.fetch(userId);
        sysUser.setSignatureUrl(signatureUrl);

        sysUserService.update(sysUser);
        sysUserService.cacheRemove(sysUser.getId());

        return Result.success();
    }


    /**
     * 用户列表查询（用于后台管理系统）
     * Add by LJT 2023-10-9
     */
    @At("/listForBM")
    @Ok("json:{locked:'^(password|salt)$',ignoreNull:false}")
    @POST
    @ApiOperation(name = "获取用户列表")
    @ApiFormParams(
            {
                    @ApiFormParam(name = "unitPath", example = "", description = "单位PATH"),
                    @ApiFormParam(name = "postId", example = "", description = "职务ID"),
                    @ApiFormParam(name = "username", example = "", description = "用户姓名"),
                    @ApiFormParam(name = "loginname", example = "", description = "用户名"),
                    @ApiFormParam(name = "mobile", example = "", description = "手机号码"),
                    @ApiFormParam(name = "sex", example = "0", description = "性别"),
                    @ApiFormParam(name = "province", example = "", description = "省份"),
                    @ApiFormParam(name = "city", example = "", description = "市"),
                    @ApiFormParam(name = "district", example = "", description = "区县"),
                    @ApiFormParam(name = "county", example = "", description = "乡镇"),
                    @ApiFormParam(name = "community", example = "", description = "社区"),
                    @ApiFormParam(name = "unitName", example = "", description = "单位"),
                    @ApiFormParam(name = "department", example = "", description = "部门"),
                    @ApiFormParam(name = "channel", example = "", description = "渠道"),
                    @ApiFormParam(name = "disabled", example = "", description = "用户状态", type = "boolean"),
                    @ApiFormParam(name = "query", example = "", description = "查询关键词"),
                    @ApiFormParam(name = "beginTime", example = "", description = "开始时间", type = "long"),
                    @ApiFormParam(name = "endTime", example = "", description = "结束时间", type = "long"),
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "createdAt", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            }
    )
    @ApiResponses(
            implementation = Pagination.class
    )
    @SLog
    // @SaCheckPermission("sys.manage.user")  因为前端需要获取所有的用户，所以先把这个注解去掉
    @SaCheckLogin
    public Result<?> listForBM(@Param("beginTime") Long beginTime,
                               @Param("endTime") Long endTime,
                               @Param("disabled") Boolean disabled,
                               @Param("mobile") String mobile,
                               @Param("sex") Integer sex,
                               @Param("unitPath") String unitPath,
                               @Param("postId") String postId,
                               @Param("username") String username,
                               @Param("loginname") String loginname,
                               @Param("province") String province,
                               @Param("city") String city,
                               @Param("district") String district,
                               @Param("county") String county,
                               @Param("community") String community,
                               @Param("unitName") String unitName,
                               @Param("department") String department,
                               @Param("channel") String channel,
                               @Param("query") String query,
                               @Param("pageNo") int pageNo,
                               @Param("pageSize") int pageSize,
                               @Param("pageOrderName") String pageOrderName,
                               @Param("pageOrderBy") String pageOrderBy) {
        Cnd cnd = Cnd.NEW();
        // 先根据用户ID查询所属辖区，再根据辖区限制查询内容
        String userId = SecurityUtil.getUserId();
        if (StringUtils.isBlank(userId)) {
            return Result.error("用户查询异常！");
        }
        Sys_user sysUser = sysUserService.fetch(userId);
        // 获取不到辖区信息不查询
/*        if (!"b9e96c8da6164034b7d2ab62f9c761b2".equals(sysUser.getUnitId())) {
            if (StringUtils.isBlank(sysUser.getProvince()) || StringUtils.isBlank(sysUser.getCity())
                    || StringUtils.isBlank(sysUser.getDistrict()) || StringUtils.isBlank(sysUser.getCounty())
                    || StringUtils.isBlank(sysUser.getCommunity())) {
                return Result.error("未查询到用户数据！");
            }
        }*/
        if (StringUtils.isNotBlank(sysUser.getProvince()) && !"直属".equals(sysUser.getProvince())) {
            cnd.and("province", "like", "%" + sysUser.getProvince() + "%");
        }
        if (StringUtils.isNotBlank(sysUser.getCity()) && !"直属".equals(sysUser.getCity())) {
            cnd.and("city", "like", "%" + sysUser.getCity() + "%");
        }
        if (StringUtils.isNotBlank(sysUser.getDistrict()) && !"直属".equals(sysUser.getDistrict())) {
            cnd.and("district", "like", "%" + sysUser.getDistrict() + "%");
        }
        if (StringUtils.isNotBlank(sysUser.getCounty()) && !"直属".equals(sysUser.getCounty())) {
            cnd.and("county", "like", "%" + sysUser.getCounty() + "%");
        }
        if (StringUtils.isNotBlank(sysUser.getCommunity()) && !"直属".equals(sysUser.getCommunity())) {
            cnd.and("community", "like", "%" + sysUser.getCommunity() + "%");
        }

        // add by LJT 增加页面查询功能 2023-10-25
        if (StringUtils.isNotBlank(province)) {
            cnd.and("province", "like", "%" + province + "%");
        }
        if (StringUtils.isNotBlank(city)) {
            cnd.and("city", "like", "%" + city + "%");
        }
        if (StringUtils.isNotBlank(district)) {
            cnd.and("district", "like", "%" + district + "%");
        }
        if (StringUtils.isNotBlank(county)) {
            cnd.and("county", "like", "%" + county + "%");
        }
        if (StringUtils.isNotBlank(community)) {
            cnd.and("community", "like", "%" + community + "%");
        }

        if (Strings.isNotBlank(unitPath)) {
            cnd.and("unitPath", "like", unitPath + "%");
        }
        if (Strings.isNotBlank(postId)) {
            cnd.and("postId", "=", postId);
        }
        if (sex != null) {
            cnd.and("sex", "=", sex);
        }
        if (channel != null) {
            cnd.and("channel", "=", channel);
        }
        if (Strings.isNotBlank(username)) {
            cnd.and("username", "like", "%" + username + "%");
        }
        if (Strings.isNotBlank(loginname)) {
            cnd.and("loginname", "like", "%" + loginname + "%");
        }
        if (Strings.isNotBlank(mobile)) {
            cnd.and("mobile", "like", "%" + mobile + "%");
        }
        if (Strings.isNotBlank(username)) {
            cnd.and("username", "like", "%" + username + "%");
        }
        if (Strings.isNotBlank(unitName)) {
            cnd.and("unit_name", "like", "%" + unitName + "%");
        }
        if (Strings.isNotBlank(department)) {
            cnd.and("department", "like", "%" + department + "%");
        }
        if (beginTime != null && endTime != null) {
            cnd.and("createdAt", ">=", beginTime);
            cnd.and("createdAt", "<=", endTime);
        }
        if (disabled != null) {
            cnd.and("disabled", "=", disabled);
        }
        if (Strings.isNotBlank(query)) {
            cnd.and(Cnd.exps("loginname", "like", "%" + query + "%").or("username", "like", "%" + query + "%")
                    .or("mobile", "like", "%" + query + "%"));
        }
        if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
            cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
        }
        Pagination pagination = sysUserService.listPage(pageNo, pageSize, cnd);
        return Result.data(pagination);
    }

    /**
     * 删除用户（用于后台管理系统）
     * Add by LJT 2023-10-9
     */
    @At("/deleteForBM/{id}")
    @Ok("json")
    @DELETE
    //@SaCheckPermission("sys.manage.user.delete")
    @SLog(value = "删除用户:${loginname}")
    @ApiOperation(name = "删除用户")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", description = "主键ID", in = ParamIn.PATH)
            }
    )
    @ApiFormParams(
            {
                    @ApiFormParam(name = "loginname", description = "用户名", required = true, check = true)
            }
    )
    @ApiResponses
    public Result<?> deleteForBM(String id, @Param("loginname") String loginname, HttpServletRequest req) {
        if (GlobalConstant.DEFAULT_SYSADMIN_LOGINNAME.equals(loginname)) {
            return Result.error("超级管理员不可删除");
        }
        Sys_user sysUser = sysUserService.getUserById(id);
        sysUserService.deleteUser(id);
        Cnd cnd = Cnd.NEW();
        cnd.and("customer_phone", "=", sysUser.getLoginname());
        List<Sqfw_servicerecord> list = sqfwServicerecordService.query(cnd);
        for (Sqfw_servicerecord sqfwServicerecord : list) {
            sqfwServicerecordService.deleteServiceOrderLogic(sqfwServicerecord.getId());
        }
        return Result.success();
    }

    @At("/uploadFile")
    @Ok("json")
    @POST
    //@SaCheckPermission("sys.manage.user.delete")
    //@SLog(value = "删除用户:${loginname}")
    @ApiOperation(name = "文件检测")
    @ApiImplicitParams()
    @ApiResponses
    public Result uploadFile(@Param("file") String file) throws IOException {

        File outFilePath2 = new File(file);
        fileDetection.uploadFileDetection(outFilePath2);

        SysOss uploadresultWord = sysOssService.upload(FileUtil.file(file));

        Map<String, Object> mapPath = new HashMap<>();
        mapPath.put("uploadresultPdf", sysOssToString(uploadresultWord));

        return Result.data(mapPath);
    }

    private static String sysOssToString(SysOss sysOss) {
        Map<String, Object> resultMap = Maps.newHashMap();
        sysOss.setFileName(sysOss.getOriginalName());
        resultMap.put("data", sysOss);
        return com.alibaba.fastjson.JSONObject.toJSONString(resultMap);
    }

    /**
     * 查询用户表中省市区5级信息（用于后台管理系统）
     */
    @At("/queryAreaInfo")
    @Ok("json")
    @POST
    @ApiOperation(name = "获取用户5级信息列表")
    @ApiFormParams(
            implementation = SysUserAreaVO.class
    )
    @ApiResponses(
            implementation = SysUserAreaVO.class
    )
    @SLog
    @SaCheckLogin
    public Result<?> queryAreaInfo(@Param("userId") String userId, @Param("..") SysUserAreaVO sysUserArea) {
        List<SysUserAreaVO> resultAreaInfo = sysUserService.queryAreaInfo(userId, sysUserArea);
        if (ObjectUtil.isEmpty(resultAreaInfo)) {
            return Result.data(ResultCode.NULL_DATA_ERROR);
        }
        return Result.data(resultAreaInfo);
    }

    /**
     * 刷新用户缓存信息（用于后台管理系统）
     *
     * @return
     */
    @At("/refresCache")
    @Ok("json")
    @PUT
    @SLog(value = "刷新缓存")
    @ApiOperation(name = "刷新缓存")
    @ApiResponses
    @SaCheckLogin
    public Result<?> refresCache() {
        String userId = SecurityUtil.getUserId();
        Sys_user sysUser = sysUserService.fetch(userId);
        if (ObjectUtil.isEmpty(sysUser)) {
            return Result.success();
        }
        sysUserService.cacheRemove(userId);
        return Result.success();
    }

    /**
     * 新建用户(后台管理系统)
     *
     * @param user
     * @return
     */
    @At("/createForAdmin")
    @Ok("json")
    @POST
    @SLog(value = "新增用户,用户名:${user.loginname}")
    @ApiOperation(name = "新增用户")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "roleIds", description = "角色ID数组")
            },
            implementation = SysUserForAdminDTO.class
    )
    @ApiResponses
    @SaCheckLogin
    public Result<?> createForAdmin(@Param("..") SysUserForAdminDTO user) {
        String adminSysUserId = SecurityUtil.getUserId();
        int checkNumber = 0;
        if (Strings.isNotBlank(user.getMobile())) {
            checkNumber = sysUserService.count(Cnd.where("mobile", "=", user.getMobile()));
            if (checkNumber > 0) {
                return Result.error("手机号已存在");
            }
        }
        checkNumber = sysUserService.count(Cnd.where("loginname", "=", Strings.trim(user.getLoginname())));
        if (checkNumber > 0) {
            return Result.error("用户名已存在");
        }
        if (Strings.isNotBlank(user.getEmail())) {
            checkNumber = sysUserService.count(Cnd.where("email", "=", Strings.trim(user.getEmail())));
            if (Strings.isNotBlank(Strings.trim(user.getEmail())) && checkNumber > 0) {
                return Result.error("邮箱已存在");
            }
        }
        Sys_user newSysUser = sysUserService.createForAdmin(user);
        return Result.success();
    }

    /**
     * 用户信息修改（后台管理系统）
     *
     * @param user
     * @param roleIds
     * @return
     */
    @At("/updateForAdmin")
    @Ok("json")
    @POST
    @SLog(value = "修改用户,用户名:${user.loginname}")
    @ApiOperation(name = "修改用户")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "roleIds", description = "角色ID数组")
            },
            implementation = Sys_user.class
    )
    @ApiResponses
    @SaCheckLogin
    public Result<?> updateForAdmin(@Param("..") Sys_user user, @Param("roleIds") String[] roleIds) {
        int checkNumber = 0;
        if (Strings.isNotBlank(user.getMobile())) {
            checkNumber = sysUserService.count(Cnd.where("mobile", "=", user.getMobile()).and("id", "<>", user.getId()));
            if (checkNumber > 0) {
                return Result.error("手机号已存在");
            }
        }
        if (Strings.isNotBlank(user.getLoginname())) {
            checkNumber = sysUserService.count(Cnd.where("loginname", "=", Strings.trim(user.getLoginname())).and("id", "<>", user.getId()));
            if (checkNumber > 0) {
                return Result.error("用户名已存在");
            }
        }
        if (Strings.isNotBlank(user.getEmail())) {
            checkNumber = sysUserService.count(Cnd.where("email", "=", Strings.trim(user.getEmail())).and("id", "<>", user.getId()));
            if (Strings.isNotBlank(Strings.trim(user.getEmail())) && checkNumber > 0) {
                return Result.error("邮箱已存在");
            }
        }
        if (user.isDisabled() && GlobalConstant.DEFAULT_SYSADMIN_LOGINNAME.equals(Strings.trim(user.getLoginname()))) {
            return Result.error("超级管理员不可禁用");
        }
        user.setUpdatedBy(SecurityUtil.getUserId());
        sysUserService.updateForAdmin(user, roleIds);
        return Result.success();
    }

    /*
     * 2.0用户批量导入
     *
     * @param file
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "单个文件上传")
    @SLog(tag = "单个文件上传", value = "${args[0]},${args[1]}")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "file", example = "1", description = "文件")
            }
    )
    @AdaptBy(type = UploadAdaptor.class)
    @SaCheckLogin
    public Result<?> uploadUserInfo2(@Param("file") TempFile file) {
        if (file.getSize() <= 0) {
            return Result.error("文件不能为空！");
        }
        if (!file.getFile().getName().endsWith(".xlsx")) {
            return Result.error("文件格式不正确！");
        }
        // 解析导入文件
        long startTime = System.currentTimeMillis();
        SqfwInfoDataEasyExcelListener<SysUserDownloadBO> listener = new SqfwInfoDataEasyExcelListener<>();
        try {
            EasyExcel.read(file.getInputStream(), SysUserDownloadBO.class, listener).sheet(0).doReadSync();
            List<SysUserDownloadBO> data = listener.getData();
            String userId = SecurityUtil.getUserId();
            List<Sys_user> finalData = new ArrayList<Sys_user>();
            for (SysUserDownloadBO summaryBO : data) {
                SysUserForAdminDTO sysUserForAdminDTO = new SysUserForAdminDTO();
                BeanUtil.copyProperties(summaryBO, sysUserForAdminDTO);
                int userCount = sysUserService.count(Cnd.where(Sys_user::getLoginname, "=", sysUserForAdminDTO.getMobile()).and(Sys_user::getDelFlag, "=", false));
                if (userCount > 0) {
                    log.info("用户已存在：{}", sysUserForAdminDTO.getMobile());
                    continue;
                }
                sysUserForAdminDTO.setId(R.UU32());
                sysUserForAdminDTO.setCreatedBy(SecurityUtil.getUserId());
                sysUserForAdminDTO.setCreatedAt(DateUtil.date().getTime());
                sysUserForAdminDTO.setUnitName(sysUserForAdminDTO.getProvince()
                        + sysUserForAdminDTO.getCity()
                        + sysUserForAdminDTO.getDistrict()
                        + sysUserForAdminDTO.getCounty()
                        + sysUserForAdminDTO.getCommunity());
                sysUserForAdminDTO.setUserLevel("0");
                sysUserForAdminDTO.setLoginname(sysUserForAdminDTO.getMobile());
                if (StringUtils.isEmpty(sysUserForAdminDTO.getPassword())) {
                    sysUserForAdminDTO.setPassword("Xy" + sysUserForAdminDTO.getMobile());
                }
                sysUserForAdminDTO.setRemark("导入数据");
                sysUserForAdminDTO.setCreatedBy(userId);
                sysUserForAdminDTO.setCreatedAt(DateUtil.date().getTime());
                sysUserForAdminDTO.setLoginname(sysUserForAdminDTO.getMobile());
                sysUserService.createForAdmin(sysUserForAdminDTO);
            }
            int importNum = listener.getData().size();
            if (0 < importNum) {
                return Result.success("成功导入数据 " + importNum + " 条");
            } else {
                return Result.error("无有效数据导入");
            }
        } catch (Exception e) {
            log.error("导入异常： {}", e.getMessage());
        } finally {
            listener.clear();
        }
        return Result.data(ResultCode.SUCCESS);
    }

    /*
     * 3.0用户批量导入
     *
     * @param file
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "单个文件上传")
    @SLog(tag = "单个文件上传", value = "${args[0]},${args[1]}")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "file", example = "1", description = "文件")
            }
    )
    @AdaptBy(type = UploadAdaptor.class)
    @SaCheckLogin
    public Result<?> uploadUserInfo(@Param("file") TempFile file, SysUserVO sysUserVO) {
        return Result.data(sysUserService.uploadUserInfo(file, sysUserVO));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "重置用户密码")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", description = "用户ID", in = ParamIn.PATH)
            }
    )
    @ApiResponses
    @SaCheckLogin
    public Result<?> resetPwdForAdmin(@Param("rsaKey") String rsaKey, @Param("operaterPwd") String operaterPwd, @Param("newPwd") String newPwd, @Param("userId") String userId) {
        sysUserService.resetPwdForAdmin(rsaKey, operaterPwd, newPwd, userId);
        return Result.success();
    }
}
